//
//  MeHomeHeaderView.m
//  OnionHome
//
//  Created by fengjie on 2019/9/13.
//  Copyright © 2019 FengJie. All rights reserved.
//

#import "MeHomeHeaderView.h"
#import "UpAndDownTitleView.h"
#import "EditorPersonalInformation.h"
#import "FansAndAttentionController.h"
#import "WonThePraiseController.h"
#import "PersonalHomePageArticleController.h"
#import "PersonalHomePageBasseController.h"

@interface MeHomeHeaderView ()
/**图像*/
@property (nonatomic,strong)UIImageView*iconImage;
/**名字*/
@property (nonatomic,strong)UILabel*nameLabel;

/**文章*/
@property (nonatomic,strong)UpAndDownTitleView*oneView;
/**粉丝*/
@property (nonatomic,strong)UpAndDownTitleView*twoView;
/**关注*/
@property (nonatomic,strong)UpAndDownTitleView*thereView;
/**获赞*/
@property (nonatomic,strong)UpAndDownTitleView*fourView;


@end

@implementation MeHomeHeaderView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = KWhiteColor;
        [self createUI];
    }
    return self;
}

/**
 进入个人信息编辑页面
 */
-(void)pushPersonInforemVC{
    [[self getCurrentViewController].navigationController pushViewController:[EditorPersonalInformation new] animated:YES];
}

/// 跳转到个人主页
-(void)pushPersonaHomeVC{
    PersonalHomePageBasseController * vc = [[PersonalHomePageBasseController alloc] init];
    vc.type = PersonalHomePageMe;
    [[self getCurrentViewController].navigationController pushViewController:vc animated:YES];
}
/// 跳转文章页面
-(void)pushArticleAction{
    PersonalHomePageBasseController * vc = [PersonalHomePageBasseController new];
    vc.selectIndex = 1;
    vc.type = PersonalHomePageMe;
    [[self getCurrentViewController].navigationController pushViewController:vc animated:YES];
}
/// 跳转粉丝页面
-(void)pushFansAction{
    FansAndAttentionController * vc = [FansAndAttentionController new];
    vc.type = FansType;
    [[self getCurrentViewController].navigationController pushViewController:vc animated:YES];

}

/// 跳转关注页面
-(void)pushAttentionAction{
    FansAndAttentionController * vc = [FansAndAttentionController new];
    vc.type = AttentionType;
    [[self getCurrentViewController].navigationController pushViewController:vc animated:YES];

}
/**
 跳转获赞页面
 */
-(void)pushWonPraiseAtion{
    [[self getCurrentViewController].navigationController pushViewController:[WonThePraiseController new] animated:YES];
}
-(void)createUI{
    
    UIImageView * moreImage = [[UIImageView alloc] initWithImage:IMAGE_NAMED(@"more")];
    moreImage.userInteractionEnabled = YES;
    [moreImage addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(pushPersonInforemVC)]];

    [self addSubview:self.iconImage];
    [self addSubview:self.nameLabel];
    [self addSubview:moreImage];
    
    [self addSubview:self.oneView];
    [self addSubview:self.twoView];
    [self addSubview:self.thereView];
    [self addSubview:self.fourView];

    [self.iconImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.top.mas_equalTo(80);
        make.width.height.mas_equalTo(72);
    }];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.iconImage);
        make.left.mas_equalTo(self.iconImage.mas_right).offset(5);
        make.right.mas_equalTo(moreImage.mas_left);
    }];
    [moreImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.iconImage);
        make.right.mas_equalTo(-16);
        make.width.mas_equalTo(7);
        make.height.mas_equalTo(9);
    }];
    CGFloat width = (KScreenWidth - 40 - 30)/4;
    CGFloat sep = 10;
    [self.oneView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.top.mas_equalTo(self.iconImage.mas_bottom).offset(20);
        make.width.mas_equalTo(width);
    }];
    [self.twoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.oneView.mas_right).offset(sep);
        make.top.mas_equalTo(self.oneView);
        make.width.mas_equalTo(width);
    }];
    [self.thereView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.twoView.mas_right).offset(sep);
        make.top.mas_equalTo(self.oneView);
        make.width.mas_equalTo(width);
    }];
    [self.fourView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.thereView.mas_right).offset(sep);
        make.top.mas_equalTo(self.oneView);
        make.width.mas_equalTo(width);
    }];

}
#pragma mark ---懒加载
-(UIImageView*)iconImage{
    if(!_iconImage){
        _iconImage=[UIImageView new];
        _iconImage.layer.cornerRadius = 36;
        _iconImage.image = IMAGE_NAMED(@"userIconDefut");
        _iconImage.layer.masksToBounds = YES;
        _iconImage.image = IMAGE_NAMED(@"user2");
        _iconImage.userInteractionEnabled = YES;
        [_iconImage addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(pushPersonaHomeVC)]];
    }
    return _iconImage;
}
-(UILabel*)nameLabel{
    if(!_nameLabel){
        _nameLabel=[UILabel new];
        _nameLabel.text = @"小是一个购物狂";
        _nameLabel.textColor = UIColorFromRGB(0x333639);
        _nameLabel.font = BOLDSYSTEMFONT(21);
        _nameLabel.userInteractionEnabled = YES;
        [_nameLabel addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(pushPersonInforemVC)]];

    }
    return _nameLabel;
}
-(UpAndDownTitleView*)oneView{
    if(!_oneView){
        _oneView=[[UpAndDownTitleView alloc] initWithFrame:CGRectZero];
        _oneView.topTitle.text = @"20";
        _oneView.bottomTitle.text=@"文章";
        _oneView.userInteractionEnabled = YES;
        [_oneView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(pushArticleAction)]];
    }
    return _oneView;
}
-(UpAndDownTitleView*)twoView{
    if(!_twoView){
        _twoView=[[UpAndDownTitleView alloc] initWithFrame:CGRectZero];
        _twoView.topTitle.text = @"2.2w";
        _twoView.bottomTitle.text=@"粉丝";
        _twoView.userInteractionEnabled = YES;
        [_twoView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(pushFansAction)]];
    }
    return _twoView;
}
-(UpAndDownTitleView*)thereView{
    if(!_thereView){
        _thereView=[[UpAndDownTitleView alloc] initWithFrame:CGRectZero];
        _thereView.topTitle.text = @"2.2w";
        _thereView.bottomTitle.text=@"关注";
        [_thereView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(pushAttentionAction)]];

    }
    return _thereView;
}
-(UpAndDownTitleView*)fourView{
    if(!_fourView){
        _fourView=[[UpAndDownTitleView alloc] initWithFrame:CGRectZero];
        _fourView.topTitle.text = @"9";
        _fourView.bottomTitle.text=@"获赞";
        [_fourView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(pushWonPraiseAtion)]];

    }
    return _fourView;
}

@end
